﻿
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>2. 设置报表显示列</title>
    <link href="../../Comm/Style/Table0.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript" >

        //页面启动函数.
        $(function () {

            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");

        });

        function InitPage() {

            var rptNo = unescape(GetQueryString("RptNo"));
            var flowNo = unescape(GetQueryString("FK_Flow"));

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", rptNo);
            handler.AddPara("FK_Flow", flowNo);
            var data = handler.DoMethodReturnString("S2ColsChose_Init");

            if (data.indexOf("@") == 0) {
                alert(data);
                return;
            }

            var jsData = JSON.parse(data);
            var Sys_MapAttrOfAll = jsData["Sys_MapAttrOfAll"]; //所有的列.
            var Sys_MapAttrOfSelected = jsData["Sys_MapAttrOfSelected"]; //已经选择的列.
            var Sys_MapAttrOfSystem = jsData["Sys_MapAttrOfSystem"]; //系统字段.
            var rptMark = rptNo.substr(('ND' + parseInt(flowNo) + 'Rpt').length);
            var dis = ' disabled="disabled"';
            var tsysAppend = "",
                        tallAppend = "";

            //1.列出系统字段（过滤掉必选字段）
            $.grep(Sys_MapAttrOfSystem, function (item) {
                return item.KeyOfEn == "Title" || item.KeyOfEn == "OID";
            }, true).forEach(function (item, index) {

                if (index % 3 == 0) {
                    tsysAppend += "<tr>";
                }

                tsysAppend += "<td nowrap style='width: 33%'>";
                var flag = false;
                var disstr = '';

                switch (rptMark) {
                    case "My":
                        if (item.KeyOfEn == "FlowStarter") {
                            flag = true;
                            disstr = dis;
                        }
                        break;
                    case "MyDept":
                        if (item.KeyOfEn == "FK_Dept") {
                            flag = true;
                            disstr = dis;
                        }
                        break;
                    case "MyJoin":

                        break;
                }

                for (var i = 0, length = Sys_MapAttrOfSelected.length; i < length; i++) {
                    if (item.KeyOfEn == Sys_MapAttrOfSelected[i].KeyOfEn && item.Name == Sys_MapAttrOfSelected[i].Name) {
                        flag = true;
                        break;
                    }
                }
                tsysAppend += "<input id='" + item.KeyOfEn + "' type='checkbox' name='" + item.KeyOfEn + "' " + (flag ? "checked = 'checked'" : "") + disstr + " />";
                tsysAppend += "<label for='" + item.KeyOfEn + "'>" + item.Name + "(" + item.KeyOfEn + ")</label>";
                tsysAppend += "</td>";

                if (index % 3 == 2) {
                    tsysAppend += "</tr>";
                }
            });
            $("#tsys").append(tsysAppend);

            //2.列出业务字段
            $.grep(Sys_MapAttrOfAll, function (item) {
                var flag = false;
                for (var i = 0, length = Sys_MapAttrOfSystem.length; i < length; i++) {
                    if (item.KeyOfEn == Sys_MapAttrOfSystem[i].KeyOfEn && item.Name == Sys_MapAttrOfSystem[i].Name) {
                        flag = true;
                        break;
                    }
                }
                return flag;
            }, true).forEach(function (item, index) {

                if (index % 3 == 0) {
                    tallAppend += "<tr>";
                }

                tallAppend += "<td nowrap style='width: 33%'>";
                var flag = false;
                for (var i = 0, length = Sys_MapAttrOfSelected.length; i < length; i++) {
                    if (item.KeyOfEn == Sys_MapAttrOfSelected[i].KeyOfEn && item.Name == Sys_MapAttrOfSelected[i].Name) {
                        flag = true;
                        break;
                    }
                }
                tallAppend += "<input id='" + item.KeyOfEn + "' type='checkbox' name='" + item.KeyOfEn + "' " + (flag ? " checked = 'checked'" : "") + "  />";
                tallAppend += "<label for='" + item.KeyOfEn + "'>" + item.Name + "(" + item.KeyOfEn + ")</label>";
                tallAppend += "</td>";

                if (index % 3 == 2) {
                    tallAppend += "</tr>";
                }
            });

            $("#tall").append(tallAppend);

        }

        function Save() {

            var checkBoxIDs = GetSelectedCheckIDs();
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_RptDfine");
            handler.AddPara("RptNo", GetQueryString("RptNo"));
            handler.AddPara("FK_Flow", GetQueryString("FK_Flow"));
            handler.AddPara("Fields", checkBoxIDs);

            var data = handler.DoMethodReturnString("S2ColsChose_Save");
            alert(data)
            if (window.opener != null) {
                //刷新父窗口
                window.opener.location.reload();
            }
        }

        //获得所有的checkbox 的id组成一个string用逗号分开, 以方便后台接受的值保存.
        function GetSelectedCheckIDs() {

            var checkBoxIDs = "";
            var arrObj = document.getElementsByTagName("input");

            for (var i = 0,len = arrObj.length; i < len;i++) {

                if (arrObj[i].type == 'checkbox') {
                    if (arrObj[i].checked)
                        checkBoxIDs += arrObj[i].id + ',';
                }
            }
            return checkBoxIDs;
        }

    </script>
    <base target="_self" /> 
</head>
<body class="easyui-layout">
    <form id="form1" method="post">
    <div data-options="region:'center',title:'2. 设置报表显示列',border:false" style="padding: 5px;
        height: auto">

        <table id="tsys" class='Table' style="width:90%" cellpadding='2' cellspacing='2'>
            <tr>
                <td class='GroupTitle' colspan="3">
                    系统字段
                </td>
            </tr>
            <tr>
                <td nowrap style='width: 33%'>
                        <input id="OID" type="checkbox" name="OID"
                            checked="checked" disabled="disabled" /><label for="OID">WorkID(OID)</label>
                </td>
                <td nowrap style='width: 33%'>
                        <input id="Title" type="checkbox" name="Title"
                            checked="checked" disabled="disabled" /><label for="Title">标题(Title)</label>
                </td>
                <td nowrap style='width: 33%'>
                        <!--<input id="WFSta" type="checkbox" name="WFSta"
                            checked="checked" disabled="disabled" /><label for="WFSta">状态(WFSta)</label>-->
                </td>
            </tr>
        </table>
        
        <table id="tall" class='Table' style="width:90%" cellpadding='2' cellspacing='2'>
            <tr>
                <td class='GroupTitle' colspan="3">
                    业务字段
                </td>
            </tr>
        </table>
        <br />
        <a id="Btn_Save" class="easyui-linkbutton" data-options="iconCls:&#39;icon-save&#39;"
            href="javascript:Save()">保存</a>
        <br />
        <br />
    </div>
    </form>
</body>
</html>
